<template>
  <el-header>
    <div class="header-container">
      <el-row :gutter="10">
        <el-col :span="3">
          <el-link :style="$route.name === 'index'? { color: '#f7c46c', backgroundColor: 'hsla(0,0%,100%,.12)' }: { color: 'hsla(0,0%,100%,.8)' }" @click.prevent="$router.push('/')">首页</el-link>
        </el-col>
<!--        <el-col :span="5">-->
<!--          <el-link :style="$route.name === 'openApi'? { color: '#f7c46c', backgroundColor: 'hsla(0,0%,100%,.12)' }: { color: 'hsla(0,0%,100%,.8)' }" @click.prevent="$router.push('/openApi')">开放api</el-link>-->
<!--        </el-col>-->
      </el-row>
    </div>
  </el-header>
  <el-main>
    <router-view />
  </el-main>
  <el-footer>&copy;&nbsp;极强臻科技有限公司</el-footer>
</template>

<script setup>
import { onUnmounted, ref, watch } from 'vue'

let refYOffset = ref()
window.addEventListener('scroll',()=>{
  refYOffset.value = window.pageYOffset
},false)

watch(refYOffset,(newVal,oldVal) => {
  if(newVal<oldVal){
    document.querySelector('.el-header').classList.add('is-sticky')
    document.querySelector('.el-header').classList.remove('is-downing')
  }else{
    document.querySelector('.el-header').classList.remove('is-sticky')
    document.querySelector('.el-header').classList.add('is-downing')
  }
})
onUnmounted(()=>{
  window.removeEventListener('scroll',()=>{},false)
})
</script>

<style lang="less" scoped>
.is-sticky{
  transition: all .3s;
  transform: translateY(0);
}
.is-downing{
  transform: translateY(-100%);
  transition: all .3s;
}
.el-header,
.el-footer {
  width: 100%;
  height: unset !important;
  line-height: 60px;
}

.el-header {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 999;
  background-color: #346cb0;
  color: hsla(0, 0%, 100%, 0.8);
  border-bottom: 1px solid rgba(61, 61, 61, 0.15);
  .header-container {
    max-width: 1000px;
    margin: 0 auto;
    .el-row {
      width: 500px;
      height: inherit;
      /deep/.el-col {
        height: inherit;
        .el-link {
          height: 35px;
          padding: 0 10px;
          border-radius: 5px;
          transition: all 0.2s ease-in;
          position: relative;
          &:hover {
            border-radius: 5px;
            background-color: hsla(0, 0%, 100%, 0.12);
          }
        }
      }
    }
  }
}

.el-main {
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  padding: 60px 0 0;
  background-color: #f5f5f5;
}

.el-footer {
  border-top: 1px solid #3d3d3d26;
  text-align: center;
}
</style>
